import { useEffect, useRef } from "react";

const useDebounce = (fn, delay) => {
    const timer = useRef(null);

    useEffect(() => {
        return () => {
             clearInterval(timer.current)
        }
    }, [])

    return (...arg) => {
        clearInterval(timer.current)
        timer.current = setTimeout(() => {
            fn(...arg)
        }, delay)
    }

}

export default useDebounce;